package com.shortvedio.search.api;

import com.shortvedio.base.context.BaseContext;
import com.shortvedio.search.service.VideosService;
import com.shortvedio.base.model.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class VideosController {

    @Autowired
    private VideosService videosService;

    @GetMapping("get_like_vedio_list")//获取喜欢的列表
    public Result getLikeVedioList(Integer page,Integer size){
        Long userId = BaseContext.getCurrentId();
        Result likeVedio = videosService.getLikeVedio(userId, page, size);
        return likeVedio;
    }

    @GetMapping("get_recommend_vedio_list")//获取推荐列表
    public Result getRecommendVedioList(){
        Long userId = BaseContext.getCurrentId();
        //推荐方式--获取喜欢的3条记录---1个从redis中获取--剩余随机获取
        Result recommendVedioList = videosService.getRecommendVedioList(userId);
        return recommendVedioList;
    }

    @GetMapping("get_favorites_vedio_list")//获取收藏夹中的视频
    public Result getFavoritesVedioList(@RequestParam Long favoritesId,@RequestParam  Integer page,@RequestParam  Integer size){
        Long userId = BaseContext.getCurrentId();
        Result favoritesVedioList = videosService.getFavoritesVedioList(favoritesId, page, size,userId);
        return favoritesVedioList;
    }

    @GetMapping("get_self_vdeio_list")//获取自己的视频列表
    public  Result getSelfVdeioList(@RequestParam Integer status){
        Long userId = BaseContext.getCurrentId();
        Result selfVdeioList = videosService.getSelfVdeioList(userId, status);
        return selfVdeioList;
    }

    @GetMapping("get_search_vedio")//搜索视频
    public Result getSearchVedio(String keyword){
        Long userId = BaseContext.getCurrentId();
        Result searchVedio = null;
        try {
            searchVedio = videosService.getSearchVedio(keyword,userId);
        } catch (IOException e) {
            return Result.error("搜索异常");
        }
        return searchVedio;
    }

    @GetMapping("get_hot_vedio")//获取热门视频
    public Result getHotVedio(@RequestParam Integer page,@RequestParam Integer size){
        Long userId = BaseContext.getCurrentId();
        Result hotVedio = videosService.getHotVedio(userId, page, size);
        return hotVedio;
    }

    @GetMapping("get_type_vedio")//获取指定类型的视频
    public Result getTypeVedio(@RequestParam Integer type,@RequestParam Integer page,@RequestParam Integer size){
        Long userId = BaseContext.getCurrentId();
        Result typeVedio = videosService.getTypeVedio(userId, type, page, size);
        return typeVedio;
    }


    @GetMapping("get_one_videos")
    public Result getOneVideos(Long videoId){
        Long userId = BaseContext.getCurrentId();
        Result oneVideos = videosService.getOneVideos(videoId, userId);
        return oneVideos;
    }



}
